package cn.btks.commonserver.valid.impl;

import cn.btks.commonserver.valid.EnumIntVaild;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.Arrays;

/**
 * Created by zhangjing on 2019/4/9.
 */
public class EnumIntVaildImpl implements ConstraintValidator<EnumIntVaild, Integer> {

    private int[] valueArr = null;

    @Override
    public void initialize(EnumIntVaild constraintAnnotation) {
        this.valueArr = constraintAnnotation.value();
    }

    @Override
    public boolean isValid(Integer value, ConstraintValidatorContext constraintValidatorContext) {
        if (value == null)
            return true;
        System.out.println(Arrays.asList(valueArr).contains(value));
        for (int i : valueArr) {
            if (i == value) {
                return true;
            }
        }
        return false;
    }

}
